<?php
ob_start();
session_start();
include("UserIncludes/DbConfig.php");
$mode = $_POST['mode'];
if($mode=='create_advertise')
{
	if($_REQUEST['ad_type']=='banner')
	{
		$select_mobile_ad_image="select * from temp_image_upload where user_id = '".$_SESSION['siteuserId']."' order by image_id desc";
		$exe_mobile_ad_image=mysql_query($select_mobile_ad_image);
		$row_mobile_ad_image=mysql_fetch_array($exe_mobile_ad_image);
		$ad_image_name=$row_mobile_ad_image['image_name'];
		//echo "<script>alert('".$ad_image_name."')</script>";
		mysql_query("delete from temp_image_upload where user_id = '".$_SESSION['siteuserId']."'");
	}
	################################ starts ################
	$str_country='';
	for($i=0;$i<count($_REQUEST[country_mobile]);$i++)
	{
		if($_REQUEST[country_mobile][$i] != 0 || $_REQUEST[country_mobile][$i] != ''){

			if(count($_REQUEST[country_mobile])>1)
			{
				if($i==count($_POST[country_mobile])-1)
				{
					$str_country.=$_REQUEST[country_mobile][$i];
				}
				else
				{
					$str_country.=$_REQUEST[country_mobile][$i].",";
				}
			}
			else
			{
				$str_country.=$_REQUEST[country_mobile][$i];
			}
		}
	}

	$query = 'INSERT INTO create_mobile_ad(user_id,ad_type,ad_name,bid_price,ad_text,link_to,country_id,ad_image)
			  VALUES("'.$_SESSION['siteuserId'].'","'.$_REQUEST['ad_type'].'","'.$_REQUEST['ad_name'].'","'.$_REQUEST['bid_price'].'","'.$_REQUEST['ad_text'].'","'.$_REQUEST['destinationUrl'].'","'.$str_country.'","'.$ad_image_name.'")';
	if(!mysql_query($query))
	{
		$_SESSION['error'] ="insert sql error.";
		main();
	}else{
		echo "<script>parent.parent.GB_hide();</script>";
	}
}
else
{
	main();
}
function main()
{
	?>
<script type="text/javascript" src="JavaScripts/jquery-1.4.2.min.js"></script>
<script language="javascript" src="js/ajax.js"></script>
<script language="javascript" src="js/ajaxresponse.js"></script>
<script language="javascript" src="JavaScripts/common.js"></script>
<script language="javascript" src="JavaScripts/TreeCheckNodeUI.js"></script>
<link href="css/new_global.css" rel="stylesheet" type="text/css">
<link href="css/create_ad.css" rel="stylesheet" type="text/css">
<link href="css/ext-all.css" rel="stylesheet" type="text/css">
<link href="css/xtheme-gray.css" rel="stylesheet" type="text/css">
<script language="JavaScript">
function selfclose()
{
//self.close();
parent.parent.GB_hide();
}
function IsNumeric(strString)
//check for valid numeric strings
{
	var strValidChars = "0123456789";
	var strChar;
	var blnResult = true;
	
	if (strString.length == 0) return false;
	
	//  test strString consists of valid characters listed above
	for (i = 0; i < strString.length && blnResult == true; i++)
	{
		strChar = strString.charAt(i);
		if (strValidChars.indexOf(strChar) == -1)
		{
			blnResult = false;
		}
	}
	return blnResult;
}

function create_ad()
{
	if(document.myAccountForm.bid_price.value =="")
	{
		alert("Please enter Bid Price.");
		document.getElementById("bid_price").focus();
		return false;
	}else
	{
		number = document.myAccountForm.bid_price.value;
		if(!IsNumeric(number))
		{
			alert("Please Enter Numeric Value As Bid Price.");
			document.getElementById("bid_price").focus();
			return false;	
		}
	}
	if(document.myAccountForm.ad_name.value =="")
	{
		alert("Please Enter Ad Name.");
		document.getElementById("ad_name").focus();
		return false;
	}
	if(document.myAccountForm.ad_text.value =="" && document.myAccountForm.ad_type.value == 'text')
	{
		alert("Please Enter Ad Text.");
		document.getElementById("ad_text").focus();
		return false;
	}
	if(document.myAccountForm.destinationUrl.value =="")
	{
		alert("Please Enter The Link.");
		document.getElementById("destinationUrl").focus();
		return false;
	}
	document.myAccountForm.mode.value='create_advertise';
	document.myAccountForm.submit();
	return true;
}
function show_mobile_set(id)
{
	//alert(id);
	for(var i =1; i<=4;i++)
	{
// 		if(document.getElementById('content_'+i))
// 		{
			if(i == id)
			{
				//alert('aaa');
				document.getElementById('content_'+i).style.display = 'block';	
			}
			else
			{
				document.getElementById('content_'+i).style.display = 'none';	
			}

		//}
		
	}
	
}


jQuery('document').ready(function(){
	
	jQuery('select[name=ad_type]').each(function(){
		val = jQuery.trim(jQuery(this).find('option:selected').val());
		prew  = jQuery(this).parents('tr.mobile');
		if(val=="text"){
			prew.find('tr.ad-text').show();
			prew.find('tr.ad-images').hide();
			prew.find('tr.text_preview').show();
			prew.find('tr.preview').hide();
		}else{
			prew.find('tr.ad-images').show();
			prew.find('tr.ad-text').hide();
			prew.find('tr.text_preview').hide();
			prew.find('tr.preview').show();
		}
	});
	
	
	jQuery('input[name=bid_price]').die('keyup');
	jQuery('input[name=bid_price]').live('keyup',function(){
		val = jQuery(this).val();
		prew  = jQuery(this).parents('tr.mobile');
		prew.find('div.addPrice').text(val);
	});
	jQuery('input[name=ad_name]').die('keyup');
	jQuery('input[name=ad_name]').live('keyup',function(){
		val = jQuery(this).val();
		prew  = jQuery(this).parents('tr.mobile');
		prew.find('div.addName').text(val);
	});
	
	jQuery('textarea[name=ad_text]').die('keyup');
	jQuery('textarea[name=ad_text]').live('keyup',function(){
		val = jQuery(this).val();
		prew  = jQuery(this).parents('tr.mobile');
		prew.find('div.addTxt').text(val);
	});
	jQuery('input[name=destinationUrl]').die('keyup');
	jQuery('input[name=destinationUrl]').live('keyup',function(){
		val = jQuery(this).val();
		prew  = jQuery(this).parents('tr.mobile');
		prew.find('div.addUrl').text(val);
	});

	jQuery('select.admob-FormDropDownBox').die('change');
	jQuery('select.admob-FormDropDownBox').live('change',function(){
		val = jQuery(this).val();
		prew  = jQuery(this).parents('tr.mobile');
		if(val=="text"){
			prew.find('tr.ad-text').show();
			prew.find('tr.ad-images').hide();
			prew.find('tr.text_preview').show();
			prew.find('tr.preview').hide();
		}else{
			prew.find('tr.ad-images').show();
			prew.find('tr.ad-text').hide();
			prew.find('tr.text_preview').hide();
			prew.find('tr.preview').show();
		}
	});
});

</script>
<form id="myAccountForm" name="myAccountForm" method="post" action="" onsubmit="return regformvalidation();"><input type="hidden" name="mode" value="" />
	<table width="100%" border="0" cellpadding="0" cellspacing="0" class="admob-Height">
		<tr class="mobile">
			<td valign="top" style="padding:5px;">
				<table width="100%" border="0" cellpadding="0" cellspacing="0" class="admob-Height">
					<tr>
						<td width="600" valign="top">
							<table width="100%" border="0" cellpadding="0" cellspacing="0" class="admob-Height">
								<tr>
									<td class="admob-SquareBoxTilteBg">Create Ad</td>
								</tr>
								<tr>
									<td valign="top" class="admob-SquareBoxBorder">
										<table width="100%" border="0" cellspacing="0" cellpadding="0">
											<tr>
												<td>
													<table width="100%" border="0" cellpadding="0" cellspacing="0" class="admob-FormContent">
														<tr>
															<td width="162" height="25">Select Ad Type :</td>
															<td>
																<select class="admob-FormDropDownBox" id="ad_type" name="ad_type" onchange="show_text_image()">
																	<option value="text">Text</option>
																	<option value="banner">Banner</option>
																</select>
															</td>
														</tr>
													</table>
												</td>
											</tr>
											
											<tr>
												<td>
													<table width="100%" border="0" cellspacing="0" cellpadding="0" id="adText_module">

														<tr>
															<td>
																<table width="100%" border="0" cellpadding="0" cellspacing="0" class="admob-FormContent">
																	<tr>
																		<td width="162" height="28">Enter Bid Price :</td>
																		<td><input name="bid_price" id="bid_price" maxlength="30" type="text" class="admob-InputBoxsmallest" /></td>
																	</tr>
																	<tr id="row_alert_adName" style="display: none">
																		<td width="162">&nbsp;</td>
																		<td align="left" id="error_adName" style="color: #FF0000; font-weight: bold; font-size: 11px;"></td>
																	</tr>
																	<tr>
																		<td height="28">Ad Name :</td>
																		<td><input name="ad_name" id="ad_name" maxlength="60" type="text" onkeyup="return preview_heading();" onkeyup="return preview_heading();" class="admob-FromInputBox" /></td>
																	</tr>
																	<tr id="row_alert_adText" style="display: none">
																		<td width="162">&nbsp;</td>
																		<td align="left" id="error_adText" style="color: #FF0000; font-weight: bold; font-size: 11px;"></td>
																	</tr>
																	<tr class="ad-text">
																		<td valign="top">Ad Text :</td>
																		<td valign="top"><textarea name="ad_text" class="admob-TextareaSmall" id="ad_text" rows="3" cols="35" onkeyup="return preview_text_description_func();"></textarea><br />
																		<span class="admob-FormSmallContent">Use the %phn% tag to insert the user's phone modelinto the text<br /> of your ad. (35 char max)</span></td>
																	</tr>
																	<tr class="admob-FormContent" id="link_url_existing_div">
																		<td height="28">Destination URL :</td>
																		<td><input name="destinationUrl" id="destinationUrl" type="text" class="admob-FromInputBox" /></td>
																	</tr>
																</table>
															</td>
														</tr>
													</table>
												</td>
											</tr>
											<tr class="ad-images">
												<td>
													<table width="100%" border="0" cellspacing="0" cellpadding="0" id="image_section" >
														<tr><td colspan="2" height="5">&nbsp;</td></tr>
														<tr>
															<td width="162" valign="top" class="admob-FormContent"><strong>Image (optional) :</strong></td>
															<td valign="top">
																<table width="100%" border="0" cellspacing="0" cellpadding="0">
																	<tr>
																		<td class="admob-SquareBoxTilteBg1">
																			<table width="96%" border="0" align="center" cellpadding="0"
																				cellspacing="0">
																				<tr>
																					<td class="admob-leftPanelWhiteContent">Images</td>
																					<td align="right"><a href="#" class="admob-ImgToplink">Add
																					or Edit Images</a></td>
																				</tr>
																			</table>
																		</td>
																	</tr>
																	<tr>
																		<td valign="top" class="admob-SquareBoxBorder">
																			<table width="100%" border="0" cellspacing="0" cellpadding="0">
																				<tr>
																					<td height="20" class="admob-BlueBoldContent">Upload new
																					Image</td>
																				</tr>
																				<tr>
																					<td>
																						<table width="100%" border="0" cellspacing="0" cellpadding="0">
																							<tr>
																								<td class="admob-FormBorder">
																									<table width="100%" border="0" cellpadding="0" cellspacing="0">
																										<tr>
																											<td>
																												<table width="100%" border="0" cellspacing="0" cellpadding="0">
																													<tr>
																														<td><input name="MAX_FILE_SIZE" value="75000" type="hidden"> <span id="fileInput"> 
																															<iframe src="upload.php" align="top" frameborder="0" scrolling="no" width="390px" height="110px" allowtransparency="true"></iframe> </span> 
																															<inpUT type="hidden" name="sahara" value="11"> 
																														</td>
																													</tr>
																												</table>
																											</td>
																										</tr>
																										<tr>
																											<td height="20" class="admob-FormSmallContent">(Allowed
																											filetypes: *.jpg, *.jpeg, *.png) Upload size:(150 X
																											100)px</td>
																										</tr>
																									</table>
																								</td>
																							</tr>
																						</table>
																					</td>
																				</tr>
																				<tr>
																					<td><img src="images/spacer.gif" alt="" width="10"
																						height="7" /></td>
																				</tr>
																				<tr>
																					<td>
																						<table width="100%" border="0" cellspacing="0" cellpadding="0">
																							<tr>
																								<td class="admob-FormBorder">
																									<table width="100%" border="0" cellpadding="0" cellspacing="0" class="admob-BlueBoldContent" id="imageSections">
																										<tr>
																											<td height="20">XL - 300x50</td>
																										</tr>
																										<tr>
																											<td><img src="images/admob-300x50img.jpg" alt=""
																												width="300" height="50" id="xl_img" /><input
																												name="xl_image_url" id="xl_image_url"
																												class="image_url" type="hidden"></td>
																										</tr>
																										<tr>
																											<td height="20">Large - 216x36</td>
																										</tr>
																										<tr>
																											<td><img id="l_img" src="images/admob-216x36img.jpg"
																												alt="" width="216" height="36" /><input
																												name="l_image_url" id="l_image_url" class="image_url"
																												type="hidden"></td>
																										</tr>
																										<tr>
																											<td height="20">Medium - 168x28</td>
																										</tr>
																										<tr>
																											<td><img id="m_img" src="images/admob-168x28img.jpg"
																												alt="" width="168" height="28" /> <input
																												name="m_image_url" id="m_image_url" class="image_url"
																												type="hidden"></td>
																										</tr>
																										<tr>
																											<td height="20">Small - 120x20</td>
																										</tr>
																										<tr>
																											<td><img id="s_img" src="images/admob-120x20img.jpg"
																												alt="" width="120" height="20" /><input
																												name="s_image_url" id="s_image_url" class="image_url"
																												type="hidden"></td>
																										</tr>
																									</table>
																								</td>
																							</tr>
																						</table>
																					</td>
																				</tr>
																			</table>
																		</td>
																	</tr>
																</table>
															</td>
														</tr>
													</table>
												</td>
											</tr>
											<tr><td colspan="2" height="5">&nbsp;</td></tr>
											<tr>
												<td>
													<table width="100%" border="0" cellspacing="0" cellpadding="0">
														<tr>
														<?php
														$SQL_country="select * from country";
														$EXE_country=mysql_query($SQL_country);
														?>
															<td width="162" valign="top" class="admob-FormContent"><strong>Select
															Targeting Country :</strong></td>
															<td valign="top"><select class="admob-LargeTextfield"
																name="country_mobile[]" id="country_mobile" multiple="true">
																<option value="" selected="selected">Select Country</option>
																<?php
																while($ROW_country=mysql_fetch_array($EXE_country))
																{
																	?>
																<option
																	value="<?php echo $ROW_country[countries_iso_code_2]; ?>"><?php echo $ROW_country[countryName]?></option>
																	<?php
																}
																?>
															</select></td>
														</tr>
													</table>
												</td>
											</tr>
											<tr>
												<td>&nbsp;</td>
											</tr>
											<tr>
												<td align="center"><input id="create_ad_submit" name="Submit22"
													type="button" class="admob-InputButton" value="Create Ad"
													onclick="create_ad()" /></td>
											</tr>
										</table>
									</td>
								</tr>
							</table>
						</td>
						<td width="11" valign="top">&nbsp;</td>
						<td width="302" valign="top">
							<table width="100%" border="0" cellspacing="0" cellpadding="0">
								<tr class="text_preview">
									<td>
										<table width="100%" border="0" cellspacing="0" cellpadding="0" id="text_preview">
											<tr>
												<td class="admob-SquareBoxTilteBg">Prewiew</td>
											</tr>
											<tr>
												<td style="padding-left:5px;padding-bottom:5px;" id="prev_heading">
													<div class="addPrice" style="width:100%;"></div>
													<div class="addName" style="width:100%;"></div>
													<div class="addTxt" style="width:100%;"></div>
													<div class="addUrl" style="width:100%;"></div>
													<div class="addCountry" style="width:100%;"></div>
												</td>
											</tr>
				
											<tr>
												<td align="center" id="preview_text_description"></td>
											</tr>
											<tr>
												<td class="admob-SquareBoxBorder admob-FormContent">Please note:
												The Preview will not display correctly if you do not set the
												"Text size" to "Normal" on your browser.</td>
											</tr>
										</table>
									</td>
								</tr>
								<tr class="preview">
									<td>
									<table width="100%" border="0" cellspacing="0" cellpadding="0" id="preview" >
										<tr>
											<td>
												<table width="100%" border="0" cellspacing="0" cellpadding="0">
													<tr>
														<td>
															<table border="0" cellspacing="0" cellpadding="0">
																<tr>
																	<td width="29" id="Nav1" onclick="show_mobile_set(1)"><img
																		src="images/admob-SButton.jpg" alt="" width="29"
																		height="22" /></td>
																	<td width="3">&nbsp;</td>
																	<td width="29" id="Nav2" onclick="show_mobile_set(2)"><img
																		src="images/admob-MButton.jpg" alt="" width="29"
																		height="22" /></td>
																	<td width="3">&nbsp;</td>
																	<td width="29" id="Nav3" onclick="show_mobile_set(3)"><img
																		src="images/admob-LButton.jpg" alt="" width="29"
																		height="22" /></td>
																	<td width="3">&nbsp;</td>
																	<td width="29" id="Nav4" onclick="show_mobile_set(4)"><img
																		src="images/admob-XLButton.jpg" alt="" width="29"
																		height="22" /></td>
																</tr>
															</table>
														</td>
													</tr>
													<tr>
														<td><img src="images/spacer.gif" alt="" width="10" height="8" /></td>
													</tr>
													<tr>
														<td><img src="images/admob-300x50img.jpg" alt="" width="300"
															height="50" /></td>
													</tr>
													<tr>
														<td><img src="images/spacer.gif" alt="" width="10" height="8" /></td>
													</tr>
												</table>
											</td>
										</tr>
										<tr class="preview_content selected" id="content_1"
											style="display: block; width: 120; height: 20">
											<td class="admob-FormContent"><strong>Mobile Website</strong><br />
											</td>
										</tr>
										<tr class="preview_content" id="content_2"
											style="display: none; width: 168; height: 28;">
											<TD class="admob-FormContent"><strong>Mobile Website</strong><br />
											</TD>
										</tr>
										<tr class="preview_content" id="content_3"
											style="display: none; width: 216; height: 36;">
											<TD class="admob-FormContent"><strong>Mobile Website</strong><br />
											</TD>
										</tr>
										<tr class="preview_content" id="content_4"
											style="display: none; width: 300; height: 50;">
											<TD class="admob-FormContent"><strong>Mobile Website</strong><br />
											</TD>
										</tr>
									</table>
								</td>
							</tr>
						</table>
					</td>
				</tr>
			</table>
		</td>
	</tr>
</table>
</form>
<?php

}
?>
